package com.eastfair.enums;

import com.eastfair.annotation.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * <p>
 * 所属模块枚举类
 *
 * </p>
 *
 * @author ligang
 * @date 2021-07-29
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "ModuleTypeEnum", description = "场景类型-枚举")
public enum ModuleTypeEnum implements BaseEnum {

    /**
     * NAVIGATION_BAR="导航栏"
     */
    NAVIGATION_BAR("导航栏"),
    /**
     * HEAD_IMAGE="头图"
     */
    HEAD_IMAGE("头图"),
    /**
     * BUTTON="按钮"
     */
    BUTTON("按钮"),
    /**
     * ICON="ICON"
     */
    ICON("ICON"),
    ;
    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static ModuleTypeEnum match(String val, ModuleTypeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static ModuleTypeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(ModuleTypeEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "场景类型", allowableValues = "NAVIGATION_BAR,HEAD_IMAGE,BUTTON,ICON", example = "NAVIGATION_BAR")
    public String getCode() {
        return this.name();
    }

}
